import java.util.Stack;
//力扣155. 最小栈
class MinStack {
    Stack<Integer> stack ;
    Stack<Integer> minStack ;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    
    public void push(int val) {
        stack.push(val);
        if(minStack.empty()){
            minStack.push(val);
        }else if(minStack.peek() >= val){
            minStack.push(val);
        }
       
    }
    
    public void pop() {
        int val = stack.pop();
        if(!minStack.empty()){
            if(val == minStack.peek()){  
                minStack.pop();
            }
        }
    }
    
    public int top() {
       return stack.peek();
    }
    
    public int getMin() {
        if(minStack.empty()){
            return -1;
        }
        return minStack.peek();
    }
}